from django.db import models

from apps.setup.models import Userinfo


class Role(models.Model):
    role_id = models.BigAutoField(db_column='Role_Id', primary_key=True)
    parentroleid = models.BigIntegerField(db_column='ParentRoleId')
    rolename = models.CharField(db_column='RoleName', max_length=20)
    gentime = models.DateTimeField(db_column='GenTime')
    edittime = models.DateTimeField(db_column='EditTime')
    description = models.CharField(db_column='Description', max_length=200, blank=True, null=True)
    del_field = models.BooleanField(db_column='Del', blank=True, default=False)

    class Meta:
        db_table = 'role'
        verbose_name_plural = '角色表'


class Userconnection(models.Model):
    userconnection_id = models.BigAutoField(db_column='UserConnection_Id', primary_key=True)
    user = models.ForeignKey('Users', models.DO_NOTHING, db_column='User_Id', blank=True, null=True)
    providerid = models.CharField(db_column='providerId', max_length=255)
    provideruserid = models.CharField(db_column='providerUserId', max_length=255, unique=True)
    rank = models.IntegerField()
    displayname = models.CharField(db_column='displayName', max_length=255, blank=True, null=True)
    profileurl = models.CharField(db_column='profileUrl', max_length=512, blank=True, null=True)
    imageurl = models.CharField(db_column='imageUrl', max_length=512, blank=True, null=True)
    accesstoken = models.CharField(db_column='accessToken', max_length=512)
    secret = models.CharField(max_length=512, blank=True, null=True)
    refreshtoken = models.CharField(db_column='refreshToken', max_length=512, blank=True, null=True)
    expiretime = models.BigIntegerField(db_column='expireTime', blank=True, null=True)

    class Meta:
        db_table = 'userconnection'
        verbose_name_plural = '第三方登录信息表'


class Users(models.Model):
    user_id = models.BigAutoField(db_column='User_Id', primary_key=True)
    role = models.ForeignKey('Role', models.DO_NOTHING, db_column='Role_Id', blank=True, null=True)
    userinfo = models.ForeignKey(Userinfo, models.DO_NOTHING, db_column='UserInfo_Id', blank=True, null=True,
                                 related_name='userinfo')
    studentid = models.CharField(db_column='StudentId', max_length=20, unique=True)
    username = models.CharField(db_column='UserName', max_length=20)
    password = models.CharField(db_column='PassWord', max_length=200)
    phonenumber = models.CharField(db_column='PhoneNumber', max_length=20, blank=True, null=True)
    email = models.CharField(db_column='Email', max_length=20, blank=True, null=True)
    avatar = models.CharField(db_column='Avatar', max_length=20, blank=True, null=True)
    realname = models.CharField(db_column='RealName', max_length=20, blank=True, null=True)
    qqid = models.CharField(db_column='QqId', max_length=20, blank=True, null=True)
    weiboid = models.CharField(db_column='WeiboId', max_length=20, blank=True, null=True)
    wechatid = models.CharField(db_column='WeChatId', max_length=20, blank=True, null=True)
    gentime = models.DateTimeField(db_column='GenTime')
    edittime = models.DateTimeField(db_column='EditTime')

    class Meta:
        db_table = 'user'
        unique_together = ('studentid', 'phonenumber')
        verbose_name_plural = '用户表'
